<?php
// +----------------------------------------------------------------------
// | ThinkPHP
// +----------------------------------------------------------------------
// | Copyright (c) 2008 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
// $Id$

function loadAvgCheck() {
	// 启用系统负载检测 针对Linux环境
	if(!IS_WIN && C('LOAD_AVG_LIMIT')) {
		if($fp = @fopen('/proc/loadavg', 'r')) {
			list($loadavg) = explode(' ', fread($fp, 6));
			fclose($fp);
			if($loadavg > C('LOAD_AVG_LIMIT')) {
				header("HTTP/1.0 503 Service Unavailable");
				exit('Server is Busy now');
			}
		}
	}
}
Tag::add('app_init','loadAvgCheck');
?>